package org.dromara.tearoom.dubbo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.tearoom.api.RemoteSYWNService;
import org.dromara.tearoom.domain.TerRoomDetails;
import org.dromara.tearoom.domain.bo.TerHornLoginBo;
import org.dromara.tearoom.domain.vo.TerHornEquipmentVo;
import org.dromara.tearoom.domain.vo.TerRoomDetailsVo;
import org.dromara.tearoom.mapper.TerRoomDetailsMapper;
import org.dromara.tearoom.service.ISYWNService;
import org.dromara.tearoom.service.ITerHornEquipmentService;
import org.dromara.tearoom.service.ITerHornLoginService;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;

@RequiredArgsConstructor
@Service
@DubboService
public class RemoteSYWNServiceImpl implements RemoteSYWNService {
    private final ISYWNService sYWNService;
    private final ITerHornEquipmentService terHornEquipmentService;
    private final  ITerHornLoginService terHornLoginService;
    private final TerRoomDetailsMapper baseMapper;

    @Override
    public  void loginInfoUpdate() {

        LambdaQueryWrapper<TerRoomDetails> lqw = Wrappers.lambdaQuery();
        lqw.ne(TerRoomDetails::getStatus,"4");
        List<TerRoomDetailsVo> roomList =  baseMapper.selectVoList(lqw);

        List<TerHornEquipmentVo> eclist = terHornEquipmentService.selectEquipmentAndCookie();
        LocalDateTime now = LocalDateTime.now();
        TerHornLoginBo hlbo = null;
        for(TerRoomDetailsVo rvo:roomList){
            for(TerHornEquipmentVo vo : eclist){
                if(rvo.getId()==vo.getTeroomId()){
                    hlbo =new TerHornLoginBo();
                    hlbo.setCookieValue(sYWNService.sYWNLogin());
                    hlbo.setModifyTime(now);
                    hlbo.setDeviceId(vo.getId());
                    terHornLoginService.updateByBo(hlbo);
                }
            }
        }
    }
}
